package com.example.unitybletest;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.seventh.blekit.FromUnity;
import com.seventh.blekit.IBackListener;
import com.seventh.blekit.SensorData;
import com.seventh.blekit.fix0629.SensorDef;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn_search).setOnClickListener(this);
        findViewById(R.id.btn_connect).setOnClickListener(this);
        TextView tvVersion = findViewById(R.id.tv_android_version);
        tvVersion.setText("SDK_INT:" + Build.VERSION.SDK_INT);
        TextView data = findViewById(R.id.tv_sensordata);
        FromUnity.getInstance(this).setBackListener(new IBackListener() {
            @Override
            public void onBack(SensorData sensorData) {
                Log.e("print", sensorData.toString());
                data.setText(sensorData.toString());
            }
        });
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_search) {
            //float f1= SensorDef.func((byte)0x01,(byte)0x23);
            //float f2= SensorDef.func((byte)0x81,(byte)0x23);
            //Log.e("print",f1+"="+f2);
            FromUnity.getInstance(this).scan();
        } else if (v.getId() == R.id.btn_connect) {
            byte[] data = new byte[]{0x55, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
            //FromUnity.parseSensorData(data);
            //FromUnity.getInstance().connect();
        }
    }
}